<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <hello-world :str='str' @child-event='getSend'></hello-world>
        
    </div>

    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        Vue.component('hello-world',{
            data:function(){
                return {
                    num:10,
                }
            },
            props:['str'],
            methods:{
                sendFn(){
                    //专门触发一个事件将值传递出去
                    this.$emit('child-event',{
                        name:'张三',
                        num:this.num,
                    })
                }
            },
            template:`
                <div>
                    <h2>我是子组件内部私有数据：{{num}}</h2>
                    <h2>{{str}}</h2>
                    <p>======================</p>
                    <button @click='sendFn'>点击获取子组件数据</button>
                </div>
            `
        });
        new Vue({
            el:'#app',
            data:function(){
                return {
                    str:'我是父组件的值'
                }
            },
            methods:{
                getSend:function(p){
                    console.log('我得到了子组件的数据',p);
                }
            },
        })
    </script>
</body>
</html>